<!--
    选择组件复制之前的, 没有注释
  -->
<template>
  <div class="tabs">
    <div :class="{ tab: true, active: isActive === index }" v-for="(item, index) in list" :key="item.id"
      @click="tabSecondActive(index, item.start, item.end)">{{ item.name }}
    </div>
    <choose-range @getDateObj="getDateObj"></choose-range>
  </div>
</template>

<script>
import ChooseRange from './chooseRange/ChooseRange'
import { mapGetters } from 'vuex'
export default {
  name: 'Ranking',
  components: {
    ChooseRange
  },
  data() {
    return {
      list: [
        { id: 1, name: '前20名', start: 1, 'end': 20 },
        { id: 2, name: '后20名', start: 276, 'end': 295 }
      ],
      isActive: 0
    }
  },
  computed: {
    ...mapGetters(['selectRange'])
  },
  mounted(){
    this.tabSecondActive(this.isActive);
  },
  methods: {
    tabSecondActive(index) {
      this.isActive = index
      this.$store.commit('SETSELECTRANGE', { start: this.list[index].start, end: this.list[index].end })
    },
    getDateObj({ startIndex, endIndex, show }) {
      this.isActive = ''
      this.$store.commit('SETSELECTRANGE', { start: startIndex, end: endIndex })
    }
  }
}
</script>

<style lang="less" scoped>
.tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  // margin-top: 2rem;
  padding: 0.14rem 0.3rem 0 0.3rem;

  .tab {
    font-size: 0.28rem;
    font-family: SourceHanSansCN-Regular, SourceHanSansCN;
    font-weight: 400;
    color: #333333;
    line-height: 0.42rem;

    &.active {
      color: #4375C9;
    }
  }
}
</style>
